export function genRandomArray(count: number, min: number, max: number, isRepeat: boolean): number[] {
  let arr: number[] = new Array(count)
  let obj = {} as any
  for (let i = 0; i < count; i++) {
    let value = random(min, max)
    if (!isRepeat && (max - min) > count) {
      if (typeof obj[value] === 'undefined') {
        arr[i] = value
        obj[value] = 1
      } else {
        i--
      }
    } else {
      arr[i] = value
    }
  }
  return arr
}

export function random(min: number, max: number) {
  return Math.floor(Math.random() * (max - min + 1) + min)
}

export function swap(arr: number[], i: number, j: number) {
  let [m, n] = [arr[i], arr[j]]
  arr[j] = m
  arr[i] = n
}

export function genSortList(count: number, min: number, max: number, sortCount: number): number[] {
  let n = count - sortCount
  let arr: number[] = new Array(count)
  for (let i = 0; i < n; i++) {
    arr[i] = i
  }
  for (let i = sortCount; i < arr.length; i++) {
    let value = random(min, max)
    arr[i] = value
  }
  return arr
}
